package com.javasm.controller.goodsController;

import com.github.pagehelper.PageInfo;
import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.goodsCriteria.GdColourCriteria;
import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.vo.goodsVo.GdColourVo;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.service.goodsService.GdColourService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/19-11:10
 * @Since:jdk1.8
 * @Description:
 */
@RestController
@RequestMapping("/colour")
@RequiredArgsConstructor
public class GdColourController extends BaseController {


    private final GdColourService gdColourService;

    /**
     * 查所有
     * @param
     * @return
     */
    @GetMapping("list")
    public AxiosResult<List<GdColour>> list(){

        List<GdColour> list = gdColourService.list();
//        System.out.println(list.toString());
        return AxiosResult.success(list);
    }


    @GetMapping("findList")
    public AxiosResult<PageResult<GdColourVo>> findList(GdColourCriteria gdColourCriteria){

        PageResult<GdColourVo> gdColourVoPageResult = gdColourService.searchCriteria(gdColourCriteria);

        return AxiosResult.success(gdColourVoPageResult);
    }


    @PostMapping("addColour")
    public AxiosResult addColour(@RequestBody GdColour gdColour){

        return AxiosResult.success(gdColourService.save(gdColour));
    }

    @PutMapping("updateColour")
    public AxiosResult updateColour(@RequestBody GdColour gdColour){
        return AxiosResult.success(gdColourService.updateById(gdColour));
    }


    @DeleteMapping("deleteById/{id}")
    public AxiosResult deleteById(@PathVariable Long id){

        int i = gdColourService.selectColourId(id);

        System.out.println(i);

        if (i>0){
            return AxiosResult.success(gdColourService.removeById(80000000));
        }else {
            return AxiosResult.success(gdColourService.removeById(id));
        }


    }

    @DeleteMapping("batchDeleteByIds/{ids}")
    public AxiosResult batchDeleteByIds(@PathVariable List<Long> ids){

        int i = gdColourService.batchDeleteByIds(ids);

        if (i>0){
            return toAxios(10);
        }{
            return toAxios(gdColourService.batchDeleteByIds(ids));
        }
    }




}
